package icasue.net.socket.driver.providers;


import icasue.net.socket.driver.mdc.MDCommandDriver;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @Author: Qiao Hang
 * @CreateDate: 2021/3/24 上午10:09
 * @UpdateDate:
 * @Description: 实现该类，提供MDCommandDriver的实现，完成客户端模型定义/change的处理与事件推送, 该类会管理被提供的MDCommandDrivers.
 */
public abstract class MDCommandDriverProvider implements CommandDriverProvider<MDCommandDriver>{

    private Set<Class<? extends MDCommandDriver>> mdCommandDriversCls = new HashSet<>();

    protected List<MDCommandDriver> mdCommandDrivers = new ArrayList<>();

    /**
     * 该类的子类均实现add方法，添加1哥或者多个MDCommandDriver 到 this.mdCommandDrivers, 由CommandDriverManager进行统一管理.
     */
    protected void add(MDCommandDriver... drivers){
        if(drivers != null && drivers.length > 0){
            for (MDCommandDriver driverIn : drivers) {
                if(driverIn != null && !mdCommandDriversCls.contains(driverIn.getClass())){
                    mdCommandDriversCls.add(driverIn.getClass());
                    mdCommandDrivers.add(driverIn);
                }
            }
        }
    };


}
